var mobile =getCookie('mobile');
var pagindex=0;
var pagesize=10;
var str = "";
function  getadlist() {
    showLoading("正在加载..","div");
    mui.post('/Article/findAll',{ pageindex:pagindex,
        pagesize:pagesize}, function (data) {
            console.log(data);
            if (data.code && data.object.length > 0) {
                var x = document.getElementById("adlist");
                for (var i in data.object) {
                    var item = data.object[i];
                    str += '<li class="mui-table-view-cell mui-media" id="';
                    str += item.id;
                    str += '">';
                    str += '<a class="mui-navigate-right"  href="addetails.html?id=';
                    str += item.id;
                    str += '">';
                    str += '<img class="mui-media-object mui-pull-left"';
                    str += ' src="'
                    str +=imgsrcpath()+ item.preimage;
                    str += '">';
                    str += '<div class="mui-ellipsis" style="font-size: 13px;">';
                    str += item.title;
                    str += '<p class="mui-media-body">';
                    str += item.pretext;
                    str += '</p>';
                    str += '</div>';
                    str += '</a>';
                    str += '</li>';
                }
                x.innerHTML = str;//改变内容
            }
            if (data.object.length%10!=0 )
            {
                hideLoading();//隐藏后的回调函数
                var x = document.getElementById("lodingshow");
                x.style.display = "block";//改变内容
                var x = document.getElementById("loding");
                x.style.display = "none";//改变内容
            }
            else {
                $("#loding").show();//表示display:none;
                var x = document.getElementById("loding");
                x.style.display = "block";//改变内容
                var x = document.getElementById("lodingshow");
                x.style.display = "none";//改变内容
                pagindex= pagindex+10;
            }
        hideLoading();//隐藏后的回调函数
        }, 'json'
    )
}


function  addagent() {
    var  userid=getCookie('userid');
    var  level=getCookie('level');
//类型:0=粉丝,1=客户,2=一级经纪人,3=代理商,4=后续经纪人',
        mui.post('/Order/findUserId', {userid:userid.toString(),typedata:"5"}, function (info) {
            console.log(info);
            //状态:0=未付款,1=已付款待确认,2=已确认待完成,3=已完成待支付尾款,4=待审核,5=完成,6=已升级
            if (!info.code||info.object==null) {
                if(level=='0'||level=='1') {
                    window.location.href = "addagent.html";
                }
                else {
                    window.location.href = "agentuser.html";
                }
            }
            else {
                var datas = info.object[0];
                if (datas.typedata == 0) {
                    mui.toast('已申请未付款，请到个人中心查看。');
                }
                if (datas.typedata == 4) {
                    mui.toast('您的申请还没有审核..');
                }
                if (datas.typedata == 5) {
                    window.location.href = "agentuser.html";
                }
            }
        });

}



function  selectfeeorder(type) {
    var  userid=getCookie('userid');
    mui.post('/Order/findUserId', {userid:userid.toString(),typedata:"0"}, function (info) {
        console.log(info);
        //状态:0=未付款,1=已付款待确认,2=已确认待完成,3=已完成待支付尾款,4=待审核,5=完成,6=已升级
        if (!info.code||info.object==null) {
            mui.alert("请您先通过免费测斑！");
            return;
        }
        else {
            var item=info.object[0];
            if (item.statustype=="4")
            {
                mui.alert("您的斑正在检测中，请耐心等待...","提示","确定","");
                return;
            }
            if (item.statustype=="7"||item.statustype=="5")
            {
                if (item.remake.indexOf("您的斑不在范围内！")>0){
                    mui.alert("抱歉，您的斑不在范围内，详情咨询客服！","提示","确定","");
                    return;
                }

                if (item.remake.indexOf("您的照片不高清")>0){
                    mui.alert("您免费测斑照片不高清，请重新检测！","提示","确定","");
                    return;
                }
                if (item.remake.indexOf("您的斑可一次根除！")>0){
                    if (type==1)
                    {
                        window.location.href=topath()+"view/jubuquban.html";
                    }
                    if (type==2)
                    {
                        window.location.href=topath()+"view/qianyuequban.html";
                    }
                }
            }
        }

    });
}


function  selectfeeorderbyid() {
    var  userid=getCookie('userid');
    mui.post('/Order/findUserId', {userid:userid.toString(),typedata:"0"}, function (info) {
        console.log(info);
        //状态:0=未付款,1=已付款待确认,2=已确认待完成,3=已完成待支付尾款,4=待审核,5=完成,6=已升级
        if (info.code&&info.object!=null) {
            var item=info.object[0];
            if (item.statustype=="4")
            {
                mui.alert("您的斑正在检测中，请耐心等待...","提示","确定","");
                return false;
            }
            else {
                window.location.href=topath()+"view/free.html";
            }
        }
        else {
            window.location.href=topath()+"view/free.html";
        }
    });
}
$(function(){
    geturlid();
    getadlist();
});






